package cn.edu.xhu.library_management.iot.controller;

import cn.edu.xhu.library_management.iot.dto.Command;
import cn.edu.xhu.library_management.iot.mqtt.client.MqttAcceptClient;
import cn.edu.xhu.library_management.iot.mqtt.client.MqttSendClient;
import com.alibaba.fastjson2.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: MMJ
 * @Date: 2023 - 04 - 16
 * @Description: 测试类
 */
@Api(tags = "iot测试模块")
@ApiSort(1)
@RestController
@RequestMapping("/lm_iot")
public class TestController {
    @Resource(name = "mqttSendClient")
    private MqttSendClient sendClient;

    @Resource(name = "mqttAcceptClient")
    private MqttAcceptClient acceptClient;

//    @GetMapping("/sub")
//    public String sub() {
//        acceptClient.connect();
////        acceptClient.subscribe("/SmartLibrary/#",0);
//        acceptClient.subscribe("/SmartLibrary/#",0);
//        return "订阅成功";
//    }
//
//    @GetMapping("/put")
//    public String put(@RequestParam("content") String content){
//        sendClient.publish(false,"/SmartLibrary/sub",content);
//        return "发送成功";
//    }

    @ApiOperation(value = "关灯",produces="application/json")
    @ApiOperationSupport(order = 111)
    @GetMapping("/offLen")
    public String offLen(){
        Command command = new Command();
        command.setLED_SW(0);
        sendClient.publish(false,"/SmartLibrary/sub",JSON.toJSONString(command));
        return "关闭灯成功";
    }
    @ApiOperation(value = "开灯",produces="application/json")
    @ApiOperationSupport(order = 112)
    @GetMapping("/onLen")
    public String onLen(){
        Command command = new Command();
        command.setLED_SW(1);
        sendClient.publish(false,"/SmartLibrary/sub",JSON.toJSONString(command));
        return "开启灯成功";
    }
}
